package com.cbs.android.component.share.umeng.entity;

import android.content.Context;
import android.graphics.Bitmap;

import com.cbs.android.component.graphicsutils.GraphicsUtils;
import com.cbs.android.component.log.L;
import com.umeng.socialize.media.UMImage;

import java.io.File;

/**
 * Created by broche on 10/22/16.
 */

public class CBSUMImage extends UMImage {
    private static final String TAG = CBSUMImage.class.getName();
    public final static int ImageWidth = 480;
    public final static int ImageQuality = 80;
    public final static int LinkImageWidth = 64;
    public final static int LinkImageQuality = 80;
    private int width = ImageWidth;
    private int quality = ImageQuality;

    public CBSUMImage(Context context, File file) {
        super(context, file);
    }

    public CBSUMImage(Context context, String s) {
        super(context, s);
    }

    public CBSUMImage(Context context, int i) {
        super(context, i);
    }

    public CBSUMImage(Context context, byte[] bytes) {
        super(context, bytes);
    }

    public CBSUMImage(Context context, Bitmap bitmap) {
        super(context, bitmap);
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getQuality() {
        return quality;
    }

    public void setQuality(int quality) {
        this.quality = quality;
    }

    @Override
    public byte[] toByte() {
        byte[] bytes = super.toByte();
        if (bytes != null) {
            byte[] cbytes = GraphicsUtils.compressBitmap(bytes, width, quality, Bitmap.CompressFormat.JPEG);
//            L.e(TAG, "tobyte: " + cbytes.length);
            return cbytes;
        } else {
//            L.e(TAG, "tobyte: " + bytes.length);
            return bytes;
        }
    }

    @Override
    public byte[] asBinImage() {
        byte[] bytes = super.asBinImage();
        if (bytes != null) {
            byte[] cbytes = GraphicsUtils.compressBitmap(bytes, width, quality, Bitmap.CompressFormat.JPEG);
//            L.e(TAG, "tobinimage: " + cbytes.length);
            return cbytes;
        } else {
//            L.e(TAG, "tobinimage: " + bytes.length);
            return bytes;
        }
    }

    //    @Override
//    public UMImage getThumbImage() {
//         super.getThumbImage();
//    }
}
